import { useEffect, useState } from 'react'
import { ChannelItem } from '@/apis/type'
import { fetchChannelAPI } from '@/apis/list'

function useTabs() {
    const [channels, setChannels] = useState<ChannelItem[]>([])

    useEffect(() => {
        getChannels()
    }, [])

    const getChannels = async () => {
        try {
            const res = await fetchChannelAPI()
            setChannels(res.data.data.channels)
        } catch (error) {
            throw new Error('fetch channel error')
        }
    }
    return {
        channels
    }
}

export { useTabs }